package club.kingyin.kyblog.core.extend;

import club.kingyin.kyblog.core.IP;
import club.kingyin.kyblog.core.utils.cache.CacheUtil;
import club.kingyin.kyblog.core.utils.log.BeforePostProcessor;
import club.kingyin.kyblog.core.utils.log.LogResult;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * @author ：kingyin
 * @date ：创建于 2021/9/11 3:13 上午
 * @description ：
 * @modified By：
 * @version: 1.0.0
 */
public class IPSetPostProcessor implements BeforePostProcessor {

    @Override
    public void resourcesSet(LogResult logResult, ProceedingJoinPoint joinPoint) {
        IP ip = joinPoint.getTarget().getClass().getDeclaredAnnotation(IP.class);
        IP tmp = CacheUtil.getAnnotation(joinPoint, IP.class);
        if (ip == null && tmp == null)
            return;
        logResult.setSources(tmp == null ? ip.value() : tmp.value());
    }
}
